package com.example.taxfloatproject20240926.ui.floatrecorder;

import android.content.Context;

import androidx.databinding.BaseObservable;

import com.example.taxfloatproject20240926.databinding.ActivityMainBinding;
import com.example.taxfloatproject20240926.ui.bean.CallBean;
import com.example.taxfloatproject20240926.ui.room.CallInterface;
import com.example.taxfloatproject20240926.ui.room.CallRepository;

import java.util.List;


/**
 * Created by zjt on 18-1-19.
 */

public class MainActivityViewModel extends BaseObservable implements CallInterface<CallBean> {
    private Context context;
    private ActivityMainBinding mainBinding;
    private FloatNormalView floatNormalView;
    private FloatControlView floatControlView;

    private boolean isControlVisible = false;

    public MainActivityViewModel(Context context, ActivityMainBinding mainBinding,
                                 FloatControlView.OnSureClickListener onSureClickListener,
                                 FloatControlView.OnOpenSetActivityListener openSetActivityListener) {
        this.context = context;
        this.mainBinding = mainBinding;
        init();
        if (floatControlView != null) {
            floatControlView.setOnSureClickListener(onSureClickListener);
            floatControlView.setOpenSetActivityListener(openSetActivityListener);
        }
    }

    private void init() {
        floatNormalView = new FloatNormalView(context, view -> {
            floatControlView.setLayoutParams(floatNormalView.getLayoutParams());
            floatControlView.show();
            floatNormalView.dismiss();
        });
//
        floatControlView = new FloatControlView(context, view -> {
            floatNormalView.setLayoutParams(floatControlView.getLayoutParams());
            floatNormalView.show();
            floatControlView.dismiss();
        }, isVisible -> {
            if (isControlVisible) {
                floatControlView.show();
                floatNormalView.dismiss();
            } else {
                floatControlView.dismiss();
                floatNormalView.show();
            }
        });
        floatNormalView.show();

    }

    public void connectNet(boolean isConnect) {
        if (floatControlView == null) {
            return;
        }
        floatControlView.showConnect(isConnect);
    }

    public void loadData(String msg) {
        if (floatControlView == null) {
            return;
        }
        floatControlView.loadData(msg);
    }

    public void release(){
        if (floatControlView == null) {
            return;
        }
//        floatControlView.release();
    }


    @Override
    public void addSuccess(boolean isAdd) {

    }

    @Override
    public void callList(List<CallBean> calledBeanList) {

    }
}
